package ru.xpparty.scanner;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * Socket scanner implementation
 * which performs real scanning
 * 
 * @author xp.party
 *
 */
public class SocketScannerImpl implements SocketScanner {
	private String host; 
	private int port;
	
	/**
	 * 
	 * @param host host to scan
	 * @param port port on host to scan
	 */
	public SocketScannerImpl(String host, int port) {
		this.host = host;
		this.port = port;
	}

	/**
	 * 
	 * @return status of scanned port
	 */
	@Override
	public PortStatus scan() {
		try {
			new Socket(host, port);
			return PortStatus.OPEN;
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			//FIXME: exception thrown, but socket opened - can it happen?
			return PortStatus.CLOSED;
		}
		return null;
	}
		

}
